import com.itheima.domain.User;
import com.itheima.service.UserService;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;


public class App {


    @Test
    public void findAllTest() {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = context.getBean("userService", UserService.class);

        List<User> list = userService.findAll();

        System.out.println(list);

    }

    @Test
    public void findByIdTest() {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = context.getBean("userService", UserService.class);
        User user = userService.findById(1);

        System.out.println(user);

    }

    @Test
    public void insertTest() {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = context.getBean("userService", UserService.class);
        User user = new User(10, "sun", 19);
        userService.insert(user);


    }

    @Test
    public void updateTest() {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = context.getBean("userService", UserService.class);
        User user = new User(10, "moon", 20);
        userService.update(user);


    }

    @Test
    public void deleteTest() {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = context.getBean("userService", UserService.class);

        userService.delete(10);

    }
}
